// 文本处理API服务
const API_BASE_URL = '/api/text-processing'

// 通用请求方法
const request = async (url, data = {}) => {
    try {
        const response = await fetch(`${API_BASE_URL}${url}`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify(data)
        })
        
        if (!response.ok) {
            throw new Error(`HTTP error! status: ${response.status}`)
        }
        
        return await response.json()
    } catch (error) {
        console.error('API请求失败:', error)
        throw error
    }
}

// 文本处理API
export const textProcessingAPI = {
    // 改写功能
    rewrite: async (query) => {
        return request('/other/chat', {
            conversation_id: "",
            message_id: "string",
            history_len: -1,
            history: [],
            stream: false,
            chat_model_config: {},
            tool_config: {},
            temperature: 0.7,
            max_tokens: 0,
            prompt_name: "gaixie",
            model_type: "llm_model",
            model_name: "qwen3:32b",
            query: query
        })
    },
    // 续写功能
    continueWriting: async (query) => {
        return request('/other/chat', {
            conversation_id: "",
            message_id: "string",
            history_len: -1,
            history: [],
            stream: false,
            chat_model_config: {},
            tool_config: {},
            temperature: 0.7,
            max_tokens: 0,
            prompt_name: "xuxie",
            model_type: "llm_model",
            model_name: "qwen3:32b",
            query: query
        })
    },
    // 缩写功能
    abbreviate: async (query) => {
        return request('/other/chat', {
            conversation_id: "",
            message_id: "string",
            history_len: -1,
            history: [],
            stream: false,
            chat_model_config: {},
            tool_config: {},
            temperature: 0.7,
            max_tokens: 0,
            prompt_name: "suoxie",
            model_type: "llm_model",
            model_name: "qwen3:32b",
            query: query
        })
    },
    // 翻译功能
    translate: async (query) => {
        return request('/other/chat', {
            conversation_id: "",
            message_id: "string",
            history_len: -1,
            history: [],
            stream: false,
            chat_model_config: {},
            tool_config: {},
            temperature: 0.7,
            max_tokens: 0,
            prompt_name: "fanyi",
            model_type: "llm_model",
            model_name: "qwen3:32b",
            query: query
        })
    },
    // 智能纠错
    smartCorrection: async (query) => {
        return request('/other/chat', {
            conversation_id: "",
            message_id: "string",
            history_len: -1,
            history: [],    
            stream: false,
            chat_model_config: {},
            tool_config: {},
            temperature: 0.7,
            max_tokens: 0,
            prompt_name: "jiance",
            model_type: "llm_model",
            model_name: "qwen3:32b",
            query: query
        })
    }
}

export default textProcessingAPI 